/**
 * Copyright (c) 2008, Daniel Gee. All Rights reserved.
 * See LICENSE.txt for more details.
 */
package com.rl.dungeon.fov;

import com.rl.dungeon.Location;

/**
 * A ViewBump helps track info for a View as the view is processed. It has its own location, as well
 * as tracking all previous locations.
 * 
 * @author Daniel Gee
 */
class ViewBump implements Cloneable
{
	/**
	 * The location of this ViewBump.
	 */
	public final Location location;

	/**
	 * The ViewBump that the containing View had before this one. The ViewBumps use this to form a
	 * single-linked list.
	 */
	public final ViewBump parent;

	/**
	 * Makes a new ViewBump, specifying all parameters.
	 * 
	 * @param bumpLocation
	 *            the location of this ViewBump.
	 * @param parent
	 *            the ViewBump that came before this ViewBump.
	 */
	public ViewBump(Location bumpLocation, ViewBump parent)
	{
		super();
		this.location = bumpLocation;
		this.parent = parent;
	}

	/**
	 * Cloning a ViewBump also clones the parent of the ViewBump in the process, all the way up the
	 * chain until the parent is null.
	 */
	@Override
	public ViewBump clone()
	{
		return new ViewBump(this.location, (this.parent == null ? null : this.parent.clone()));
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
		{
			return true;
		}
		if (obj == null)
		{
			return false;
		}
		if (this.getClass() != obj.getClass())
		{
			return false;
		}
		ViewBump other = (ViewBump) obj;
		if (this.location == null)
		{
			if (other.location != null)
			{
				return false;
			}
		}
		else if (!this.location.equals(other.location))
		{
			return false;
		}
		if (this.parent == null)
		{
			if (other.parent != null)
			{
				return false;
			}
		}
		else if (!this.parent.equals(other.parent))
		{
			return false;
		}
		return true;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((this.location == null) ? 0 : this.location.hashCode());
		result = prime * result + ((this.parent == null) ? 0 : this.parent.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return "ViewBump(" + this.location.toString() + ","
				+ (this.parent == null ? "null" : "<parent>") + ")";
	}
}
